package com.sqx.modules.health.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.entity.RoleMenu;
import com.sqx.modules.health.service.IRoleMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色菜单关系表 前端控制器
 * </p>
 *
 * @author xglhappy
 * @since 2022-04-14
 */

@Api(value = "角色菜单关系表", tags = "", description = "")
@RestController
@RequestMapping("/health/role-menu")
public class RoleMenuController {
    @Autowired
    private IRoleMenuService roleMenuService;

    // 新增或更新
    @PostMapping("/save")
    @ApiOperation(value = "新增或更新角色菜单关系表", notes = "新增或更新角色菜单关系表")
    public Result save(@RequestBody RoleMenu roleMenu){
        return Result.success(roleMenuService.saveOrUpdate(roleMenu));
    }

    // 根据ID删除
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "根据ID删除角色菜单关系表", notes = "根据ID删除角色菜单关系表")
    public Result delete(@PathVariable Integer id){
        return Result.success(roleMenuService.removeById(id));
    }

    // 根据IDS删除
    @PostMapping("/del/batch")
    @ApiOperation(value = "根据IDS删除角色菜单关系表", notes = "根据IDS删除角色菜单关系表")
    public Result deleteBatch(@RequestBody List<Integer> ids){
        return Result.success(roleMenuService.removeByIds(ids));
    }

    // 查询全部
    @GetMapping("/findAll")
    @ApiOperation(value = "查询全部角色菜单关系表", notes = "查询全部角色菜单关系表")
    public Result findAll(){
        return Result.success(roleMenuService.list());
    }

    // 根据ID查询一条记录
    @GetMapping("/findOne")
    @ApiOperation(value = "根据ID查询一条记录角色菜单关系表", notes = "根据ID查询一条记录角色菜单关系表")
    public Result findOne(@RequestParam Integer id){
        return Result.success(roleMenuService.getById(id));
    }

    // 分页查询
    @GetMapping("/findPage")
    @ApiOperation(value = "分页查询角色菜单关系表", notes = "分页查询角色菜单关系表")
    public Result findPage(@RequestParam Integer pageNum,@RequestParam Integer pageSize){
        QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("id");
        return  Result.success(roleMenuService.page(new Page<>(pageNum,pageSize),queryWrapper));
    }


}

